-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DVT-1057 replace block data structure with LRU cache to fix memory leak #148
Conversation
bb7fdfd
to
2ec2ef9
Compare
ms.BlocksLock.Lock() | ||
ms.Blocks[pb.Number().String()] = pb | ||
ms.BlocksLock.Unlock() | ||
ms.BlockCache.Add(pb.Number().String(), pb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The Add method checks if the cache is at its maximum capacity.
- If the cache is full, it evicts the least recently used item before adding the new item.
- If the cache is not full, it simply adds the new item to the cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could add this in the code as a comment also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, nice job @gatsbyz!
I tested this version of polycli monitor
with a very fast refresh rate while sending a lot of transactions against an anvil node and the memory looks pretty stable! 👏
added functions
isBlockInCache
: Determines if a given block number is already available in the LRU cache to avoid unnecessary network requests.checkAndFetchMissingBlocks
: Identifies blocks not present in the cache within a specified range and fetches them from the Ethereum network to fill the cache.removed
currIdx
,selectedBlock
,Max/MinBlockRetrieved
to clean up logic variables